package com.tcd.web.controller;


import com.tcd.pojo.Permission;
import com.tcd.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 权限表 前端控制器
 * </p>
 *
 * @author space
 * @since 2021-05-21
 */
@RestController
@RequestMapping("/permission/permission")
@CrossOrigin
public class PermissionController {
    @Autowired
    PermissionService permissionService;

    @RequestMapping("getUserPermission")
    public List<Permission> getUserPermission(int uid){
        return permissionService.getUserPermission(uid);
    }

    @RequestMapping("getUserPermissionNoTree")
    public List<Permission> getUserPermissionNoTree(int uid){
        return permissionService.getUserPermissionNoTree(uid);
    }

    @RequestMapping("getPermissionFiltrate")
    public List<Permission> getPermissionFiltrate(@RequestParam(defaultValue = "1") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize, String name, Integer[] level, Integer parentId){
        return permissionService.getPermissionFilter(pageIndex,pageSize,name,level,parentId);
    }

    @RequestMapping("getPermissionFiltrateCount")
    public Integer getPermissionFiltrateCount(String name, Integer level, Integer parentId){
        return permissionService.getPermissionFilterCount(name,level,parentId);
    }

    @RequestMapping("getPermissionTree")
    public List<Permission> getPermissionTree(@RequestParam(defaultValue = "1,2,3") Integer[] levels){
        return permissionService.getPermissionTree(levels);
    }

    @RequestMapping("addPermission")
    public Integer addPermission(@RequestBody Permission permission){
        return permissionService.addPermission(permission);
    }

    @RequestMapping("updatePermission")
    public Integer updatePermission(@RequestBody Permission permission){
        return permissionService.updatePermission(permission);
    }

    @RequestMapping("delPermissions")
    public Integer delPermissions(Integer[] ids){
        return permissionService.delPermissions(ids);
    }
}

